@extends('admin.common.base-master')

@section('html-head')


@endsection

@section('html-body')
    <div id="content">
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.noticeList')}}">公告列表</a>
        </div>

        @include("admin.common.banner-header")
        <div class="filter-box clearfix">

            <div class="fr">
                <a class="addBtn" href="{{route("Admin.Home.noticeSet")}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>id</th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>描述</th>
                    <th>内容</th>
                    <th>发布时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($notices) > 0)
                    @foreach($notices as $notice )
                        <tr id="notice_{{$notice ->id}}">
                            <td>{{$notice->id}}</td>
                            <td>{{$notice->title}}</td>
                            <td>{{$notice->type}}</td>
                            <td>{{$notice->desc}}</td>
                            <td><a href="{{env("HOST_URL")}}/notice?id={{$notice->id}}" target="_blank">查看</a></td>
                            <td>{{$notice->created_at}}</td>
                           {{-- <td style="overflow: inherit">{{env("HOST_URL")}}/article?id={{$notice->id}}</td>--}}
                            <td><a class="color2" href="{{route("Admin.Home.noticeSet")}}?id={{$notice->id}}">编辑</a>
                                <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$notice->id}}">删除 </a></td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            <?php echo $notices->render();?>
        </div>

    </div>

    <script>
        $(document).on("click",".del",function(){
            var id = $(this).attr("data-id");

            noty({
                text: '你确定要删除吗?',
                buttons: [
                    {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                            $noty.close();
                            $.ajax({
                                url:'{{route('Api.Admin.sys.delNotice')}}',
                                type:'post',
                                dataType:'json',
                                data:{id:id},
                                success:function(obj){
                                    if(obj.level == "success"){
                                        $("#notice_"+id).hide('slow');
                                    }else{
                                        noty({type:obj.level,text:obj.message,timeout:600});
                                    }
                                },
                                error:function(obj){
                                    console.log(obj);
                                }

                            });
                        }
                    },
                    {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                            $noty.close();
                        }
                    }
                ]
            });

        });


    </script>
@endsection
